﻿@{
	Layout = null;
}
<link href="~/libs/layui-v2.9.21/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<div>
	<label class="layui-form-label">工作站名称</label>
	<input type="text" class="layui-input" id="workstationName" placeholder="请输入" style="width: 150px;float: left;margin-right: 10px">

	@* <div class="layui-form-item layui-form-text" style="width:350px;">
		<label class="layui-form-label">工作站名称</label>
		<div class="layui-input-block">
			<select name="suppliersname" id="workstationNameDropDown" lay-verify="required" lay-filter="workstationName">
				<option value="">请选择工作站</option>
			</select>
		</div>
	</div> *@

	<button class="layui-btn" lay-submit lay-filter="search" id="selectBtn">查询</button>
	<button class="layui-btn layui-bg-blue" lay-on="test-page">新增</button>
</div>

<div style="margin-top:20px">
	<table lay-filter="test" class="layui-hide" id="ID-table-demo-page"></table>
</div>

<script type="text/html" id="operateBtn">
	<button class="layui-btn layui-btn-sm   layui-bg-radius" style=background-color:blue lay-event="edit" >修改</button>
	<button class="layui-btn layui-btn-sm   layui-bg-radius" style=background-color:red lay-event="remove" >删除</button>
</script>
<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui-v2.9.21/layui/layui.js"></script>

<script>
		layui.use('table', function(){
		  var table = layui.table;
		  var dropdown=layui.dropdown ;

		  function initTable(){
			  table.render({
				elem: '#ID-table-demo-page',
				url:'/Workstation/GetWorkstationList', // 此处为静态模拟数据，实际使用时需换成真实接口
				page:true,
				limit:10,
				limits:[10,15,20],
				cols: [[
				//	{ type: 'checkbox', fixed: 'left' },
					{field: 'workstationCode', title: '工作站编号'},
					{field: 'workstationName', title: '工作站名称'},
					{field: 'workstationPlace', title: '工作站地点'},
					{field: 'workshopName', title: '所在车间名称'}, 
					{field: 'processBelongs', title: '所属工序'},
					{field: 'state', title: '是否启用',
					templet: function (d)
					{
						return d.state ===1? "是" : "否"
					}},
					{ field:'操作',title: '操作', width: 160,toolbar:'#operateBtn' }
				]],
				 parseData:function(res){
					console.log(res)
				 },
				 done: function (res, curr, count) {
				  console.log(res.data);
				}
				 });


				function workstationNameDropDown(){
					$.ajax({
						url:'/Workstation/GetWorkstationListRedis',
						type:'get',
						dataType:'json',
						success:function(res){
							console.log(11,res)
							$(res.data).each(function () {
							  $("#workstationNameDropDown").append('<option value="' + this.workstationName + '">' + this.workstationName + '</option>')
							})  
							  layui.form.render();
						},

					})
				}

				workstationNameDropDown();



		  }

			initTable();


			$('#selectBtn').on('click', function () {
				var workstationName = $('#workstationName').val();
				table.reload('ID-table-demo-page', {
					where: { // 设定异步数据接口的额外参数，任意设
					workstationName: workstationName||"",
					}
				});
			});

		  table.on('tool(test)',function(obj){
				layEvent = obj.event;
				data = obj.data;
				if (layEvent === 'remove') {
				layer.confirm('确定删除吗？', function (index) {
					$.ajax({
						url: "/workstation/RemoveWorkstationById",
						data: {
							id: data.id,
						},
						type: "post",
						datatype: "json",
						async: false,
						success: function (res) {
							console.log(res)
							if (res>0) {
								layer.msg('删除成功');
								initTable();
							} else {
								layer.msg('删除失败: ' + res.msg);
							}
						}
					 })
				layer.close(index); //关闭弹框
				})
			}else{
				 layer.open({
					 type:2,
					 title:'编辑',
					 area: ['1100px', '700px'],
					 shade: 0.6, // 遮罩透明度
					 shadeClose: true, // 点击遮罩区域，关闭弹层
					 maxmin: true, // 允许全屏最小化
					 anim: 0, // 0-6 的动画形式，-1 不开启
					 content:['/Workstation/UpdateWorkstationView?id='+data.id, 'no'],
					 end:function (){
						 location.reload();
					 }
				 })
			}
		})

		});

			//新增弹框
		layui.use(function(){
	  var $ = layui.$;
	  var layer = layui.layer;
	  var util = layui.util;
	  // 事件
	  util.on('lay-on', {
		'test-page': function(){
		  layer.open({
			type: 2,
			area: ['1100px', '700px'],
			title:'新增',
			skin: 'layui-layer-rim', // 加上边框
			content: ['/Workstation/AddWorkstationView', 'no'] // 数组第二个成员设为 no 即屏蔽 iframe 滚动条
		  });
		},
	  })
	});







</script>


